// Store 类型定义

import { ReactNode } from "react";

// 通用API响应类型
export interface ApiResponse<T = any> {
  status: number;
  data: T;
  message?: string;
  result?: T;
}

// 加载状态枚举
export type LoadingStatus = 'idle' | 'loading' | 'succeeded' | 'failed';

// ==================== Cart Slice 类型 ====================
export interface DemoState {
  count: number;
  userData: any;
  status: LoadingStatus;
  error: string;
  bannderList: BannerItem[];
}

export interface BannerItem {
  id: number;
  title: string;
  imageUrl: string;
  linkUrl?: string;
  sort?: number;
}

// ==================== Home Slice 类型 ====================
export interface HomeState {
  count: number;
  status: LoadingStatus;
  error: string;
  banners: BannerItem[];
  knowledgeNav: KnowledgeNavItem[];
  knowledgeList: KnowledgeItem[];
  knowledgeDetail: KnowledgeDetail;
  dragNav: DragNavItem[];
  dragList: DragItem[];
  dragDetail: DragDetail;
  consultationDoctors: DoctorItem[];
  informaitionNavs: InformationNavItem[];
  informaitionList: InformationItem[];
  lastPayloadLength: number;
  informaitiondetail: InformationDetail;
}

export interface KnowledgeNavItem {
  departmentName: ReactNode;
  id: number;
  name: string;
  icon?: string;
  sort?: number;
}

export interface KnowledgeItem {
  id: number;
  title: string;
  description?: string;
  imageUrl?: string;
  departmentId: number;
  categoryId: number;
}

export interface KnowledgeDetail {
  pathology: ReactNode;
  symptom: ReactNode;
  benefitTaboo: ReactNode;
  westernMedicineTreatment: ReactNode;
  chineseMedicineTreatment: ReactNode;
  id: number;
  title: string;
  content: string;
  imageUrl?: string;
  createTime?: string;
  updateTime?: string;
}

export interface DragNavItem {
  id: number;
  name: string;
  icon?: string;
  sort?: number;
}

export interface DragItem {
  id: number;
  title: string;
  description?: string;
  imageUrl?: string;
  navId: number;
}

export interface DragDetail {
  name: ReactNode;
  component: ReactNode;
  taboo: ReactNode;
  effect: ReactNode;
  usage: ReactNode;
  shape: ReactNode;
  packing: ReactNode;
  sideEffects: ReactNode;
  storage: ReactNode;
  minMatter: ReactNode;
  approvalNumber: ReactNode;
  id: number;
  title: string;
  content: string;
  imageUrl?: string;
  createTime?: string;
  updateTime?: string;
}

export interface DoctorItem {
  id: number;
  name: string;
  avatar?: string;
  department: string;
  title?: string;
  rating?: number;
  consultationCount?: number;
  price?: number;
}

export interface InformationNavItem {
  id: number;
  name: string;
  icon?: string;
  sort?: number;
}

export interface InformationItem {
  thumbnail: string;
  id: number;
  title: string;
  summary?: string;
  imageUrl?: string;
  navId: number;
  createTime?: string;
}

export interface InformationDetail {
  releaseTime: ReactNode;
  source: ReactNode;
  id: number;
  title: string;
  content: string;
  imageUrl?: string;
  createTime?: string;
  updateTime?: string;
}

// ==================== User Slice 类型 ====================
export interface UserState {
  count: number;
  userData: any;
  status: LoadingStatus;
  error: string;
  loginres: LoginResponse;
  registerres: RegisterResponse;
  emailCode: string;
}

export interface LoginResponse {
  token?: string;
  userId?: number;
  username?: string;
  avatar?: string;
  status?: number;
  message?: string;
}

export interface RegisterResponse {
  userId?: number;
  username?: string;
  status?: number;
  message?: string;
  pwd1?: string,
  pwd2?: string,
}

export interface LoginRequest {
  username: string;
  password: string;
  email?: string;
}

export interface RegisterRequest {
  email: string,
  code: string,
  pwd1: string,
  pwd2: string,
  invitationCode: string,
}

// ==================== Root State 类型 ====================
export interface RootState {
  dome: DemoState;
  home: HomeState;
  user: UserState;
  patientCircle: PatientCircleState;
}

// ==================== Action Payload 类型 ====================
export interface AddCartPayload {
  count: number;
}

export interface SetUserDataPayload {
  userData: any;
}

export interface SetBannerListPayload {
  banners: BannerItem[];
}

export interface SetKnowledgeNavPayload {
  knowledgeNav: KnowledgeNavItem[];
}

export interface SetKnowledgeListPayload {
  knowledgeList: KnowledgeItem[];
}

export interface SetKnowledgeDetailPayload {
  knowledgeDetail: KnowledgeDetail;
}

export interface SetDragNavPayload {
  dragNav: DragNavItem[];
}

export interface SetDragListPayload {
  dragList: DragItem[];
}

export interface SetDragDetailPayload {
  dragDetail: DragDetail;
}

export interface SetConsultationDoctorsPayload {
  consultationDoctors: DoctorItem[];
}

export interface SetInformationNavsPayload {
  informaitionNavs: InformationNavItem[];
}

export interface SetInformationListPayload {
  informaitionList: InformationItem[];
}

export interface SetInformationDetailPayload {
  informaitiondetail: InformationDetail;
}

// ==================== API 请求参数类型 ====================
export interface DoctorListParams {
  departmentId?: number;
  page?: number;
  pageSize?: number;
  keyword?: string;
}

export interface KnowledgeListParams {
  departmentId: number;
  page?: number;
  pageSize?: number;
}

export interface KnowledgeDetailParams {
  id: number;
}

export interface DragListParams {
  navId: number;
  page?: number;
  pageSize?: number;
}

export interface DragDetailParams {
  id: number;
}

export interface InformationListParams {
  navId: number;
  page?: number;
  pageSize?: number;
}

export interface InformationDetailParams {
  id: number;
}

// ==================== 病友圈相关类型 ====================

// 病友圈发布表单数据类型
export interface PatientCircleFormData {
  title: string;
  departmentId: number | null;
  disease: string;
  detail: string;
  treatmentHospital: string;
  treatmentStartTime: string;
  treatmentEndTime: string;
  treatmentProcess: string;
  amount: number | null;
}

// 病友圈发布响应类型
export interface PatientCirclePublishResponse {
  status: string;
  message: string;
  result: number;
}

// 科室/病症分类类型
export interface KnowledgeBaseItem {
  departmentName: string;
  id: number;
  pic: string;
  rank: number;
}

// 病症列表项类型
export interface DiseaseListItem {
  departmentId: number;
  id: number;
  name: string;
}

// 病友圈发帖列表项类型
export interface PatientSickCircleItem {
  sickCircleId: number;
  title: string;
  detail: string;
  amount: number;
  collectionNum: number;
  commentNum: number;
  releaseTime: number;
}

// 病友圈发帖列表参数类型
export interface PatientSickCircleListParams {
  patientUserId: number;
  page: number;
  count: number;
}

// 病友圈详情参数类型
export interface PatientCircleDetailParams {
  sickCircleId: number;
}

// 病友圈详情响应类型
export interface PatientCircleDetailResponse {
  sickCircleId: number;
  authorUserId: number;
  departmentId: number;
  adoptFlag: number;
  title: string;
  department: string;
  disease: string;
  detail: string;
  treatmentHospital: string;
  treatmentStartTime: string;
  treatmentEndTime: string;
  treatmentProcess: string;
  picture: string;
  collectionFlag: number;
  collectionNum: string;
  commentNum: number;
  adoptNickName: string;
  adoptHeadPic: string;
  adoptComment: string;
  adoptTime: number;
}

// 病友圈评论参数类型
export interface PatientCircleCommentParams {
  sickCircleId: number;
  page: number;
  count: number;
}

// 病友圈评论项类型
export interface PatientCircleCommentItem {
  commentId: number;
  userId: number;
  nickName: string;
  headPic: string;
  content: string;
  createTime: number;
  likeNum: number;
  dislikeNum: number;
  opinion: number; // 0-未表态 1-赞同 2-反对
}

// 发表评论参数类型
export interface PublishCommentParams {
  sickCircleId: number;
  content: string;
}

// 图片上传参数类型
export interface ImageUploadParams {
  sickCircleId: number;
  picture: File;
}

// 收藏病友圈参数类型
export interface SickCollectionParams {
  sickCircleId: number;
}

// 病友圈评论列表参数类型
export interface CommentListParams {
  sickCircleId: number;
  page: number;
  count: number;
}

// 赞同/反对病友圈评论参数类型
export interface ExpressOpinionParams {
  commentId: number;
  opinion: number;
}

// 病友圈发表评论参数类型
export interface PublishCommentParams {
  sickCircleId: number;
  content: string;
}

// 病友圈状态类型
export interface PatientCircleState {
  status: LoadingStatus;
  error: string;
  knowledgeBaseList: KnowledgeBaseItem[];
  diseaseList: DiseaseListItem[];
  sickCircleDetail: PatientCircleDetailResponse;
  commentList: PatientCircleCommentItem[];
  publishResult: PatientCirclePublishResponse | null;
  uploadStatus: LoadingStatus;
  uploadError: string;
}